<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录页面</title>
    <!--导入jquery的js文件-->
    <script src="/SSM_war_exploded/js/jquery-3.4.1.min.js"></script>
</head>
<body>
    <form>
        用户名:<input type="text" name="username" id="name" placeholder="请输入用户名" /><br/>
        密&ensp;&ensp;码:<input type="password" id="pwd" name="password" placeholder="请输入密码" /><br/>
        <input type="button" value="登录" id="loginBtn" />
    </form>
</body>
<script>
                //jquery的载入数据,单击点击事件
                $(function (){

                        $("#loginBtn").click(function(){

                            //获取用户名和密码
                            var $username = $("#name").val();
                            var $password = $("#pwd").val() ;

                            //发送ajax
                            $.ajax({
                                "url":"/SSM_war_exploded/user/login",
                                "type":"POST",
                                "data":JSON.stringify({username:$username,password:$password}),
                                "contentType":"application/json",
                                "success":function(data){
                                  //data-->服务器端返回的json数据
                                    if(data.code ==0){
                                        alert(data.msg) ;
                                    }else{
                                        alert(data.msg) ;
                                    }
                                },
                                "dataType":"json"
                            }) ;
                        }) ;
                }) ;

</script>
</html>